home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_5 / crvfit.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  1.1 KB  |  42 lines  |  [MATF/MATL]

  1. function Clist = crvfit(x,y,ct)
  2. % Clist = crvfit(x,y,ct)
  3. % Construct the least squares curve fit.
  4. % x is an 1xn abscissa vector, input.
  5. % y is an 1xn ordinate vector, input.
  6. % ct is the curve type, input.
  7. % Clist is the coefficient list, output.
  8. if length(ct)==0, ct=2; end
  9. L = 0;
  10. if ct==10,
  11.   clc;
  12.   disp('             Y = '),disp(y),...
  13.   disp('          y(x) = L/(1 + C exp(Ax))'),...
  14.   disp('     lim  y(x) = L'),...
  15.   disp('    x-->oo'),...
  16.   L = input('Enter the constant L = '); 
  17. end
  18. if length(L)==0, L=0; end
  19. if L <= max(y), 
  20.   L=max(y)+0.01*abs(max(y)); 
  21. end
  22. if ct==1, X=x.^(-1); Y=y; end
  23. if ct==2, X=x.*y; Y=y; end
  24. if ct==3, X=x; Y=y.^(-1); end
  25. if ct==4, X=x.^(-1); Y=y.^(-1); end
  26. if ct==5, X=log(x); Y=y; end
  27. if ct==6, X=x; Y=log(y); end
  28. if ct==7, X=log(x); Y=log(y); end
  29. if ct==8, X=x; Y=sqrt(y).^(-1); end
  30. if ct==9, X=x; Y=log(y./x); end
  31. if ct==10,X=x; Y=log(L.*y.^(-1)-1); end
  32. AB = polyfit(X,Y,1);
  33. A = AB(1);
  34. B = AB(2);
  35. C = 0; D = 0;
  36. if ct==2, C=-1/A; D=-B/A; end
  37. if ct==6, C=exp(B); end
  38. if ct==7, C=exp(B); end
  39. if ct==9, C=exp(B); D=-A; end
  40. if ct==10,C=exp(B); end
  41. Clist = [A B C D L];
  42.